﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.ComponentModel;
using System.Data;

namespace AnonsaiWPF
{
    /// <summary>
    /// Interaction logic for AnnouncInsert.xaml
    /// </summary>
    public partial class AnnouncInsert : Window, INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;// = delegate { };

        #region Properties
        private string _amid;
        public string AnonsId
        {
            get { return _amid; }
            set
            {
                if (value != _amid)
                {
                    _amid = value;
                    OnPropertyChanged("AnonsId");
                }
            }
        }
        #endregion Properties

        protected void OnPropertyChanged(string name)
        {
           // AnnouncInsert anin = new AnnouncInsert();
            //anin.AnonsId=this.AnonsId;
            //this.DataContext = anin;
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(name));
            }
        }

        public AnnouncInsert()
        {
            InitializeComponent();
            this.DataContext = this;
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = true;
            Close();
        }

        private void textBox3_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            
            SearchId idf = new SearchId();
            idf.LoadData("select id, ClipName AS 'Name' from AnonsaiClips");
            if (idf.ShowDialog() == true)
            {
                AnonsId = idf.Id;
            }
        }
    }

    public class AnonsFromIDConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null)
            {
                return "";
            }
            else
            {
                DataTable tb = Functionality.dbc.getTable("select ClipName from AnonsaiClips where id=" + value.ToString());
                if (tb.Rows.Count > 0)
                {
                    return tb.Rows[0][0].ToString();
                }
                else return "";
            }
            //return "10";
        }

        public object ConvertBack(object value, Type targetType,
            object parameter, System.Globalization.CultureInfo culture)
        {
            if (value != null)
            {
                return value.ToString();
            }
            else
            {
                return "";
            }
        }
    }
}
